//PlatformFundModel
//2020-08-25 10:59:19

package models

import (
	"git.900sui.cn/kc/base/common/functions"
	"git.900sui.cn/kc/base/common/models/base"
	"git.900sui.cn/kc/kcgin/orm"
)

//表结构体
type PlatformFundModel struct {
	Model *base.Model
	Field PlatformFundModelField
}

//表字段
type PlatformFundModelField struct {
	T_table       string `default:"platform_fund"`
	F_id          string `default:"id"`
	F_pay_channel string `default:"pay_channel"`
	F_amount      string `default:"amount"`
}

//初始化
func (p *PlatformFundModel) Init(ormer ...orm.Ormer) *PlatformFundModel {
	functions.ReflectModel(&p.Field)
	p.Model = base.NewModel(p.Field.T_table, ormer...)
	return p
}

//新增数据
func (p *PlatformFundModel) Insert(data map[string]interface{}) int {
	result, _ := p.Model.Data(data).Insert()
	return result
}

//根据payChannel更新数据
func (p *PlatformFundModel) UpdateByPayChannel(payChannel int, data map[string]interface{}) (int, error) {
	if payChannel <= 0 {
		return 0, nil
	}
	return p.Model.Where(map[string]interface{}{
		p.Field.F_pay_channel: payChannel,
	}).Data(data).Update()
}
